<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="msg">
<input type="button" onclick="send()" value="发送">
</body>
<script>
    const ws = new WebSocket("ws://localhost:8081/api/ws/test")
    ws.onopen = evt =>{
        console.log("创建连接");
    }
    ws.onclose = evt => {
        console.log("关闭连接")
    }
    ws.onmessage = evt =>{
        console.log("收到数据："+evt.data);

    }
    function send() {
        let msg = document.getElementById("msg").value
        ws.send(msg)
        document.getElementById("msg").value = "";
    }

</script>
</html>